package cn.readjava.service.impl;

import cn.readjava.dao.ArticleCategoryDao;
import cn.readjava.service.ArticleCategoryService;
import cn.readjava.bean.ArticleCategory;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@CacheConfig(cacheNames = "articleCategory")
public class ArticleCategoryServiceImpl implements ArticleCategoryService {

    @Resource
    private ArticleCategoryDao articleCategoryDao;

    @Override
    @CacheEvict(allEntries = true)
    public void deleteById(Long id) {
        articleCategoryDao.deleteById(id);
    }

    @Override
    @CacheEvict(allEntries = true)
    public ArticleCategory save(ArticleCategory ac) {
        return articleCategoryDao.save(ac);
    }

    @Override
    @Cacheable(key = "'ac-id-'+ #p0")
    public ArticleCategory getOne(Long id) {
        return articleCategoryDao.getOne(id);
    }

    @Override
    @Cacheable(key = "'ac-all'")
    public List<ArticleCategory> findAll() {
        return articleCategoryDao.findAll();
    }

}
